//----BEGIN LICENSE----//
/*****************************************************************\
** prevalentLite - sqlite3 persistence object library 
**
** Copyright (C) 2008 Philip R. Schuchardt
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program.  If not, see <http://www.gnu.org/licenses/>.
**
*****************************************************************/
//----END LICENSE----//


//Our includes
#include "plString.h"
#include "plDatabase.h"
#include "plObject.h"

//////////////////////////////////////////////// Public ////////////////////////////////////////////////////

//Constructor
plString::plString() : plData() {
    Cached = false;
}

//Constructor
plString::plString(const char* value) : plData(){
    Value = std::string(value);
    Disabled = true;
}

//Constructor
plString::plString(const std::string& value) : plData() {
    Value = value;
    Disabled = true;
}

//Copy Constructor
plString::plString(const plString& obj)  : plData(obj) {
    Copy(obj);
}

//Accessor
const std::string& plString::Data(){
    plData::GetData();
    return Value;
}

//Modifier
void plString::SetData(const std::string& value) {
    Value = value;
    plData::SetData();
}


//Operator overloading
void plString::operator=(const std::string& value) {
    SetData(value);
}

//Operator overloading
void plString::operator=(const plString& obj) {
    Copy(obj);
}

//Operator overloading
void plString::operator=(const char* value) {
    SetData(value);
}

plString::operator const std::string&() {
    return Data();
}

plString::operator std::string() {
    return Data();
}

//Binds the data with the statement
void plString::Bind(sqlite3_stmt* statement, int index) const {
    sqlite3_bind_text(statement, index, Value.c_str(), -1, SQLITE_STATIC);
}

//Gets the data from the current statement
void plString::Column(sqlite3_stmt* statement, int index) {
    const char* text = (const char*)(sqlite3_column_text(statement, index));
    if(text) {
        Value = text;
   }
}

//Does a smart copy of the object
void plString::Copy(const plString& obj) {
    SetData(obj.Value);
}


